#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月17日

@author: Administrator
'''

from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver

from like.models import Like
from like.tasks import increase_like_count

@receiver(post_save, sender=Like, dispatch_uid='like.like.created')
def like_post_save_handler(sender, instance, created, *args, **kwargs):
    '''favorite_count +1'''
    if created:
        increase_like_count.delay(instance.content_type.model_class(), [instance.object_id])


@receiver(post_delete, sender=Like, dispatch_uid='like.like.delete')
def like_post_delete_handler(sender, instance, *args, **kwargs):
    '''favorite_count -1'''
    increase_like_count.delay(instance.content_type.model_class(), [instance.object_id], -1)
